// SPDX-License-Identifier: MIT
// Copyright 2020 NXP

/**
 * @file custom.c
 *
 */

 /*********************
  *      INCLUDES
  *********************/
#include "ui.h"
#include "ui_helpers.h"
#include <stdio.h>
#include "lwip/inet.h"
#include "lvgl.h"
#include "user.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "wifi_mgmr_ext.h"
#include "wifi_mgmr.h"
#include "easyflash.h"
#include "bflb_mtd.h"
#include "queue.h"
#include "cJSON.h"
#include "sntp.h"
#include "bflb_timestamp.h"
#include "https_client.h"
#define GBD_TAG "USER"
#include <time.h>

time_t time_dat;
extern xQueueHandle queue;
//extern lv_chart_series_t * ui_Chart1_series_1;    将定义放置在ui.c和ui.h中，并在ui_Weather.c中删除定义
//extern lv_chart_series_t * ui_Chart1_series_2;
/*
ui.h
extern lv_chart_series_t * ui_Chart1_series_1;
extern lv_chart_series_t * ui_Chart1_series_2;

ui.c
lv_chart_series_t * ui_Chart1_series_1;
lv_chart_series_t * ui_Chart1_series_2;

ui_Weather.c
lv_chart_series_t * ui_Chart1_series_1    ->    ui_Chart1_series_1
lv_chart_series_t * ui_Chart1_series_2    ->    ui_Chart1_series_2

*/

weather_t weathers[7];
dayweather_t dayweather;
TaskHandle_t https_Handle;
TimerHandle_t http_timers;
static uint32_t sta_ConnectStatus = 0;
static wifi_conf_t conf =
{
    .country_code = "CN",
};
char time_buf[10];
lv_coord_t dayweather_array[7];
lv_coord_t nightweather_array[7];

char first_connect_flag = 0;
int hour_value = 0;
int min_value = 0;
int sec_value = 0;
int year_value = 1970;
int month_value = 00;
int day_value = -1;
int wday_value = 6;

int pre_day_value = -1;

char wifi_disconnect_flag = 0;
char user_weather_path[128];


/**********************
 *  STATIC VARIABLES
 **********************/
static uint16_t timers_http = 0;
static void http_hour_requst_time(TimerHandle_t timer)
{
    if (timers_http>=60*60) {  //60*60   每1小时获取一下数据
        //LOG_I("Timed to http update,start https request");
        timers_http = 0;
        vTaskResume(https_Handle);
    }
    else {
        timers_http++;
    }

}
char* week_day[7] = { "六", "日", "一","二","三","四","五"};
static void send_event(void){
    if(day_value != pre_day_value)
    {
        lv_label_set_text_fmt(ui_DATA, "%d年 周%s\n%d月%d日 ", year_value, week_day[wday_value], month_value, day_value);
        lv_calendar_set_today_date(ui_Calendar1, year_value, month_value, day_value);
        lv_calendar_set_showed_date(ui_Calendar1, year_value, month_value);
        pre_day_value = day_value;

    }

    if(hour_value==24)
    {
        lv_label_set_text_fmt(ui_LH1,"%d",0);
        lv_label_set_text_fmt(ui_LH2,"%d",0);
    }
    else
    {
        lv_label_set_text_fmt(ui_LH1,"%d",hour_value/10);
        lv_label_set_text_fmt(ui_LH2,"%d",hour_value%10);
    }
    lv_label_set_text_fmt(ui_LM1,"%d",min_value/10);
    lv_label_set_text_fmt(ui_LM2,"%d",min_value%10);
    lv_label_set_text_fmt(ui_LS1,"%d",sec_value/10);
    lv_label_set_text_fmt(ui_LS2,"%d",sec_value%10);

    sec_value++;
    if(sec_value==60)
    {
        sec_value=0;
        min_value++;
    }
    if(min_value==60)
    {
        min_value=0;
        hour_value++;
    }
    if(hour_value==0)
    {
        if(min_value==0 && (sec_value==1 || sec_value==11)) //零点后请求两次更新日期
        {
            vTaskResume(https_Handle);
            timers_http = 0;
        }
    }

    if(first_connect_flag==1)
    {
        lv_disp_load_scr(ui_Screen2);
        first_connect_flag = 2;
    }
}

/**
 * @brief 设置时间
 *
 * @param sntp_time
 * @param fac
*/
/*实际上没有使用到sntp*/
void sntp_set_time(uint32_t sntp_time, uint32_t fac)
{
    //uint32_t stamp;

    //stamp = sntp_time - 2208988800;

    //bflb_timestamp_t time_s;

    //bflb_timestamp_utc2time(stamp, &time_s);

    //hour_value = time_s.hour;
    //min_value = time_s.min;
    //sec_value = time_s.sec;
}

/**
 * @brief
 *
 * @param key
 * @return char*
*/
char* flash_get_data(char* key, uint32_t len)
{
    static char* flash_data;
    flash_data = pvPortMalloc(len);
    memset(flash_data, 0, len);

    ef_get_env_blob(key, flash_data, len, (size_t)&len);

    return flash_data;
}

/**
 * @brief
 *
 * @param key
 * @param value
*/
void flash_erase_set(char* key, char* value)
{
    size_t len = 0;
    int value_len = strlen(value);
    ef_set_and_save_env(key, value);
    memset(value, 0, strlen(value));
    ef_get_env_blob(key, value, value_len, &len);
}

void auto_connect_set_save(void)
{
    char flag = 0;
    if(lv_obj_has_state(ui_Switch1, LV_STATE_CHECKED) == 1)
	{
        flag = 1;
	}
    flash_erase_set(CONNECT_FLAG, &flag);
}


uint8_t wifi_connect(char* ssid, char* passwd)
{
    uint32_t ipv4_addr = 0;
    static char* queue_buff;
    queue_buff = pvPortMalloc(128);
    memset(queue_buff, 0, 128);
    if (NULL==ssid || 0==strlen(ssid)) {
        return 1;
    }

    if (wifi_mgmr_sta_state_get() == 1) {
        wifi_sta_disconnect();
    }
    if (wifi_sta_connect(ssid, passwd, NULL, NULL, 0, 0, 0, 1)) {
        return 4;
    }

    //等待连接成功
    sta_ConnectStatus = 0;
    for (int i = 0;i<10*30;i++) {
        vTaskDelay(100);
        switch (sta_ConnectStatus) {
            case CODE_WIFI_ON_CONNECTED:	//连接成功(表示wifi sta状态的时候表示同时获取IP(DHCP)成功，或者使用静态IP)

                break;;
            case CODE_WIFI_ON_DISCONNECT:	//连接失败（超过了重连次数还没有连接成功的状态）
                wifi_sta_disconnect();
                return 4;
            case CODE_WIFI_ON_GOT_IP:
                wifi_sta_ip4_addr_get(&ipv4_addr, NULL, NULL, NULL);

                printf("wifi connened %s,IP:%s\r\n", ssid, inet_ntoa(ipv4_addr));
                sprintf(queue_buff, "{\"ip\":{\"IP\":\"%s\"}}", inet_ntoa(ipv4_addr));

                flash_erase_set(SSID_KEY, ssid);
                flash_erase_set(PASS_KEY, passwd);

                xQueueSend(queue, queue_buff, portMAX_DELAY);
                return 0;
            default:
                //等待连接成功
                break;
        }

        if(wifi_disconnect_flag)
        {
            wifi_disconnect_flag=0;
            wifi_sta_disconnect();
            break;
        }
    }
    vPortFree(queue_buff);
    return 14; //连接超时
}

 /**
  * @brief 解析json 类型
  *
  * @param json_data
  * @return int
 */
static int cjson__analysis_type(char* json_data)
{

    cJSON* root = cJSON_Parse(json_data);

    if (root==NULL) {
        printf("[%s] is not json\r\n", __func__);

        return 0;
    }
    cJSON* wifi = cJSON_GetObjectItem(root, "WiFi");
    if (wifi) {
        cJSON_Delete(root);
        return 1;
    }
    cJSON* ip = cJSON_GetObjectItem(root, "ip");
    if (ip) {
        cJSON_Delete(root);
        return 2;
    }

    cJSON* weather = cJSON_GetObjectItem(root, "weather");
    if (weather) {
        cJSON_Delete(root);
        return 3;
    }

    cJSON* dayweather = cJSON_GetObjectItem(root, "dayweather");
    if (dayweather) {
        cJSON_Delete(root);
        return 4;
    }

    cJSON_Delete(root);
    return 0;
}

/**
 * @brief cjson_analysis_ssid
 *
 * @param json_data
 * @return char*
*/
static char* cjson_analysis_ssid(char* json_data)
{
    static char* ssid_str;
    ssid_str = pvPortMalloc(32);
    memset(ssid_str, 0, 32);
    cJSON* root = cJSON_Parse(json_data);
    if (root==NULL) {
        printf("[%s] is not json\r\n");
        return NULL;
    }
    cJSON* wifi = cJSON_GetObjectItem(root, "WiFi");
    if (wifi==NULL)return NULL;
    cJSON* ssid = cJSON_GetObjectItem(wifi, "ssid");
    memcpy(ssid_str, ssid->valuestring, sizeof(ssid->valuestring)*8);
    cJSON_Delete(root);
    return ssid_str;
}

/**
 * @brief cjson_analysis_password
 *
 * @param json_data
 * @return char*
*/
static char* cjson_analysis_password(char* json_data)
{
    static char* pass_str;
    pass_str = pvPortMalloc(32);
    memset(pass_str, 0, 32);
    cJSON* root = cJSON_Parse(json_data);
    if (root==NULL) {
        printf("[%s] is not json\r\n");
        return NULL;
    }
    cJSON* wifi = cJSON_GetObjectItem(root, "WiFi");
    if (wifi==NULL)return NULL;
    cJSON* password = cJSON_GetObjectItem(wifi, "password");
    memcpy(pass_str, password->valuestring, sizeof(password->valuestring)*8);
    cJSON_Delete(root);
    return pass_str;
}

/**
 * @brief cjson__analysis_ip
 *      解析 IP地址
 * @param cjson_data
 * @return char*
*/
static char* cjson__analysis_ip(char* cjson_data)
{
    static char* IP_str;

    IP_str = pvPortMalloc(64);
    memset(IP_str, 0, 64);

    cJSON* root = cJSON_Parse(cjson_data);
    if (root==NULL) {
        printf("[%s] is not json\r\n", __func__);
        return NULL;
    }
    cJSON* ip_s = cJSON_GetObjectItem(root, "ip");
    cJSON* ip = cJSON_GetObjectItem(ip_s, "IP");
    memcpy(IP_str, ip->valuestring, sizeof(ip->valuestring)*16);
    cJSON_Delete(root);
    return IP_str;
}

/**
 * @brief
 *
 * @param weather_data
*/
static char cjson_get_weather(char* weather_data)
{
    for (size_t i = 0; i < strlen(weather_data); i++)
    {
        printf("%c", weather_data[i]);
    }
    printf("\r\n");

    cJSON* root = cJSON_Parse(weather_data);
    if (root==NULL) {
        printf("[%s] is not json\r\n", __func__);

        return 0;
    }
    cJSON* weather_cjson = cJSON_GetObjectItem(root, "weather");

    if(cJSON_GetObjectItem(weather_cjson, "errcode") != NULL)
    {
        lv_event_send(ui_SP1Button, LV_EVENT_CLICKED, NULL);
        vTaskDelete(https_Handle);
        /*
        _ui_flag_modify(ui_SP1Button, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_Spinner1, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_Cover1, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);

        wifi_disconnect_flag=0;
        wifi_sta_disconnect();
        */
        return 0;
    }

    cJSON* city_cjsno = cJSON_GetObjectItem(weather_cjson, "city");//城市名称
    if (city_cjsno ==NULL) {

        printf("[city_cjsno ] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_data = cJSON_GetObjectItem(weather_cjson, "data");
    if (wea_data ==NULL) {

        printf("[wea_data] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_today = cJSON_GetArrayItem(wea_data, 0);//今天天气
    if (wea_today==NULL) {

        printf("[wea_today] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_tomorrow = cJSON_GetArrayItem(wea_data, 1);
    if (wea_tomorrow==NULL) {
        printf("[wea_tomorrow] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_acquired = cJSON_GetArrayItem(wea_data, 2);
    if (wea_acquired==NULL) {
        printf("[wea_acquired] is not json\r\n");

        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_today3 = cJSON_GetArrayItem(wea_data, 3);
    if (wea_today3==NULL) {
        printf("[wea_today3] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_today4 = cJSON_GetArrayItem(wea_data, 4);
    if (wea_today4==NULL) {
        printf("[wea_today4] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_today5 = cJSON_GetArrayItem(wea_data, 5);
    if (wea_today5==NULL) {
        printf("[wea_today5] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    cJSON* wea_today6 = cJSON_GetArrayItem(wea_data, 6);
    if (wea_today6==NULL) {
        printf("[wea_today6] is not json\r\n");
        cJSON_Delete(root);
        return 0;
    }
    //解析今天天气
    cJSON* today_date = cJSON_GetObjectItem(wea_today, "date");
    cJSON* today_wea = cJSON_GetObjectItem(wea_today, "wea");
    cJSON* today_wea_img = cJSON_GetObjectItem(wea_today, "wea_img");
    cJSON* today_tem_day = cJSON_GetObjectItem(wea_today, "tem_day");
    cJSON* today_tem_night = cJSON_GetObjectItem(wea_today, "tem_night");
    cJSON* today_win = cJSON_GetObjectItem(wea_today, "win");
    cJSON* today_win_speed = cJSON_GetObjectItem(wea_today, "win_speed");
    
    //解析明天的天气
    cJSON* tomorrow_date = cJSON_GetObjectItem(wea_tomorrow, "date");
    cJSON* tomorrow_wea = cJSON_GetObjectItem(wea_tomorrow, "wea");
    cJSON* tomorrow_wea_img = cJSON_GetObjectItem(wea_tomorrow, "wea_img");
    cJSON* tomorrow_tem_day = cJSON_GetObjectItem(wea_tomorrow, "tem_day");
    cJSON* tomorrow_tem_night = cJSON_GetObjectItem(wea_tomorrow, "tem_night");
    cJSON* tomorrow_win = cJSON_GetObjectItem(wea_tomorrow, "win");
    cJSON* tomorrow_win_speed = cJSON_GetObjectItem(wea_tomorrow, "win_speed");

    //解析后天的天气
    cJSON* acquired_date = cJSON_GetObjectItem(wea_acquired, "date");
    cJSON* acquired_wea = cJSON_GetObjectItem(wea_acquired, "wea");
    cJSON* acquired_wea_img = cJSON_GetObjectItem(wea_acquired, "wea_img");
    cJSON* acquired_tem_day = cJSON_GetObjectItem(wea_acquired, "tem_day");
    cJSON* acquired_tem_night = cJSON_GetObjectItem(wea_acquired, "tem_night");
    cJSON* acquired_win = cJSON_GetObjectItem(wea_acquired, "win");
    cJSON* acquired_win_speed = cJSON_GetObjectItem(wea_acquired, "win_speed");

    //解析大后天天气
    cJSON* today3_date = cJSON_GetObjectItem(wea_today3, "date");
    cJSON* today3_wea = cJSON_GetObjectItem(wea_today3, "wea");
    cJSON* today3_wea_img = cJSON_GetObjectItem(wea_today3, "wea_img");
    cJSON* today3_tem_day = cJSON_GetObjectItem(wea_today3, "tem_day");
    cJSON* today3_tem_night = cJSON_GetObjectItem(wea_today3, "tem_night");
    cJSON* today3_win = cJSON_GetObjectItem(wea_today3, "win");
    cJSON* today3_win_speed = cJSON_GetObjectItem(wea_today3, "win_speed");

    cJSON* today4_date = cJSON_GetObjectItem(wea_today4, "date");
    cJSON* today4_wea = cJSON_GetObjectItem(wea_today4, "wea");
    cJSON* today4_wea_img = cJSON_GetObjectItem(wea_today4, "wea_img");
    cJSON* today4_tem_day = cJSON_GetObjectItem(wea_today4, "tem_day");
    cJSON* today4_tem_night = cJSON_GetObjectItem(wea_today4, "tem_night");
    cJSON* today4_win = cJSON_GetObjectItem(wea_today4, "win");
    cJSON* today4_win_speed = cJSON_GetObjectItem(wea_today4, "win_speed");

    cJSON* today5_date = cJSON_GetObjectItem(wea_today5, "date");
    cJSON* today5_wea = cJSON_GetObjectItem(wea_today5, "wea");
    cJSON* today5_wea_img = cJSON_GetObjectItem(wea_today5, "wea_img");
    cJSON* today5_tem_day = cJSON_GetObjectItem(wea_today5, "tem_day");
    cJSON* today5_tem_night = cJSON_GetObjectItem(wea_today5, "tem_night");
    cJSON* today5_win = cJSON_GetObjectItem(wea_today5, "win");
    cJSON* today5_win_speed = cJSON_GetObjectItem(wea_today5, "win_speed");

    cJSON* today6_date = cJSON_GetObjectItem(wea_today6, "date");
    cJSON* today6_wea = cJSON_GetObjectItem(wea_today6, "wea");
    cJSON* today6_wea_img = cJSON_GetObjectItem(wea_today6, "wea_img");
    cJSON* today6_tem_day = cJSON_GetObjectItem(wea_today6, "tem_day");
    cJSON* today6_tem_night = cJSON_GetObjectItem(wea_today6, "tem_night");
    cJSON* today6_win = cJSON_GetObjectItem(wea_today6, "win");
    cJSON* today6_win_speed = cJSON_GetObjectItem(wea_today6, "win_speed");

    memcpy(weathers[0].city, city_cjsno->valuestring, strlen(city_cjsno->valuestring));

    memcpy(weathers[0].date, today_date->valuestring, strlen(today_date->valuestring));
    memcpy(weathers[0].wea, today_wea->valuestring, strlen(today_wea->valuestring));
    memcpy(weathers[0].wea_img, today_wea_img->valuestring, strlen(today_wea_img->valuestring));
    memcpy(weathers[0].tem_day, today_tem_day->valuestring, strlen(today_tem_day->valuestring));
    memcpy(weathers[0].tem_night, today_tem_night->valuestring, strlen(today_tem_night->valuestring));
    memcpy(weathers[0].win, today_win->valuestring, strlen(today_win->valuestring));
    memcpy(weathers[0].win_speed, today_win_speed->valuestring, strlen(today_win_speed->valuestring));    

    memcpy(weathers[1].date, tomorrow_date->valuestring, strlen(tomorrow_date->valuestring));
    memcpy(weathers[1].wea, tomorrow_wea->valuestring, strlen(tomorrow_wea->valuestring));
    memcpy(weathers[1].wea_img, tomorrow_wea_img->valuestring, strlen(tomorrow_wea_img->valuestring));
    memcpy(weathers[1].tem_day, tomorrow_tem_day->valuestring, strlen(tomorrow_tem_day->valuestring));
    memcpy(weathers[1].tem_night, tomorrow_tem_night->valuestring, strlen(tomorrow_tem_night->valuestring));
    memcpy(weathers[1].win, tomorrow_win->valuestring, strlen(tomorrow_win->valuestring));
    memcpy(weathers[1].win_speed, tomorrow_win_speed->valuestring, strlen(tomorrow_win_speed->valuestring));    

    memcpy(weathers[2].date, acquired_date->valuestring, strlen(acquired_date->valuestring));
    memcpy(weathers[2].wea, acquired_wea->valuestring, strlen(acquired_wea->valuestring));
    memcpy(weathers[2].tem_day, acquired_tem_day->valuestring, strlen(acquired_tem_day->valuestring));
    memcpy(weathers[2].tem_night, acquired_tem_night->valuestring, strlen(acquired_tem_night->valuestring));
    memcpy(weathers[2].wea_img, acquired_wea_img->valuestring, strlen(acquired_wea_img->valuestring));
    memcpy(weathers[2].win, acquired_win->valuestring, strlen(acquired_win->valuestring));
    memcpy(weathers[2].win_speed, acquired_win_speed->valuestring, strlen(acquired_win_speed->valuestring));  

    memcpy(weathers[3].date, today3_date->valuestring, strlen(today3_date->valuestring));
    memcpy(weathers[3].wea, today3_wea->valuestring, strlen(today3_wea->valuestring));
    memcpy(weathers[3].tem_day, today3_tem_day->valuestring, strlen(today3_tem_day->valuestring));
    memcpy(weathers[3].tem_night, today3_tem_night->valuestring, strlen(today3_tem_night->valuestring));
    memcpy(weathers[3].wea_img, today3_wea_img->valuestring, strlen(today3_wea_img->valuestring));
    memcpy(weathers[3].win, today3_win->valuestring, strlen(today3_win->valuestring));
    memcpy(weathers[3].win_speed, today3_win_speed->valuestring, strlen(today3_win_speed->valuestring)); 

    memcpy(weathers[4].date, today4_date->valuestring, strlen(today4_date->valuestring));
    memcpy(weathers[4].wea, today4_wea->valuestring, strlen(today4_wea->valuestring));
    memcpy(weathers[4].tem_day, today4_tem_day->valuestring, strlen(today4_tem_day->valuestring));
    memcpy(weathers[4].tem_night, today4_tem_night->valuestring, strlen(today4_tem_night->valuestring));
    memcpy(weathers[4].wea_img, today4_wea_img->valuestring, strlen(today4_wea_img->valuestring));
    memcpy(weathers[4].win, today4_win->valuestring, strlen(today4_win->valuestring));
    memcpy(weathers[4].win_speed, today4_win_speed->valuestring, strlen(today4_win_speed->valuestring));

    memcpy(weathers[5].date, today5_date->valuestring, strlen(today5_date->valuestring));
    memcpy(weathers[5].wea, today5_wea->valuestring, strlen(today5_wea->valuestring));
    memcpy(weathers[5].tem_day, today5_tem_day->valuestring, strlen(today5_tem_day->valuestring));
    memcpy(weathers[5].tem_night, today5_tem_night->valuestring, strlen(today5_tem_night->valuestring));
    memcpy(weathers[5].wea_img, today5_wea_img->valuestring, strlen(today5_wea_img->valuestring));
    memcpy(weathers[5].win, today5_win->valuestring, strlen(today5_win->valuestring));
    memcpy(weathers[5].win_speed, today5_win_speed->valuestring, strlen(today5_win_speed->valuestring)); 

    memcpy(weathers[6].date, today6_date->valuestring, strlen(today6_date->valuestring));
    memcpy(weathers[6].wea, today6_wea->valuestring, strlen(today6_wea->valuestring));
    memcpy(weathers[6].tem_day, today6_tem_day->valuestring, strlen(today6_tem_day->valuestring));
    memcpy(weathers[6].tem_night, today6_tem_night->valuestring, strlen(today6_tem_night->valuestring));
    memcpy(weathers[6].wea_img, today6_wea_img->valuestring, strlen(today6_wea_img->valuestring));
    memcpy(weathers[6].win, today6_win->valuestring, strlen(today6_win->valuestring));
    memcpy(weathers[6].win_speed, today6_win_speed->valuestring, strlen(today6_win_speed->valuestring)); 

    for(int i=0; i<7; i++)
    {   
        dayweather_array[i] = atoi(weathers[i].tem_day);
        nightweather_array[i] = atoi(weathers[i].tem_night);
    }
    
    cJSON_Delete(root);
    return 1;
}

/**
 * @brief
 *
 * @param dayweather_data
*/
static char cjson_get_dayweather(char* dayweather_data)
{
    for (size_t i = 0; i < strlen(dayweather_data); i++)
    {
        printf("%c", dayweather_data[i]);
    }
    printf("\r\n");

    cJSON* root = cJSON_Parse(dayweather_data);
    if (root==NULL) {
        printf("[%s] is not json\r\n", __func__);
        return 0;
    }

    cJSON* dayweather_cjson = cJSON_GetObjectItem(root, "dayweather");

    if(cJSON_GetObjectItem(dayweather_cjson, "errcode") != NULL)
    {
        lv_event_send(ui_SP1Button, LV_EVENT_CLICKED, NULL);
        vTaskDelete(https_Handle);
        /*
        _ui_flag_modify(ui_SP1Button, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_Spinner1, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_Cover1, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
        
        wifi_disconnect_flag=0;
        wifi_sta_disconnect();
        */
        return 0;
    }

    cJSON* city_cjsno = cJSON_GetObjectItem(dayweather_cjson, "city");//城市名称
    cJSON* date_cjsno = cJSON_GetObjectItem(dayweather_cjson, "date");//日期
    cJSON* week_cjsno = cJSON_GetObjectItem(dayweather_cjson, "week");//周
    cJSON* wea_cjsno = cJSON_GetObjectItem(dayweather_cjson, "wea");//天气
    cJSON* wea_img_cjsno = cJSON_GetObjectItem(dayweather_cjson, "wea_img");//天气图片
    cJSON* tem_cjsno = cJSON_GetObjectItem(dayweather_cjson, "tem");//实时温度
    cJSON* tem_day_cjsno = cJSON_GetObjectItem(dayweather_cjson, "tem_day");//白天温度
    cJSON* tem_night_cjsno = cJSON_GetObjectItem(dayweather_cjson, "tem_night");//夜晚温度
    cJSON* win_cjsno = cJSON_GetObjectItem(dayweather_cjson, "win");
    cJSON* win_speed_cjsno = cJSON_GetObjectItem(dayweather_cjson, "win_speed");
    cJSON* win_meter_cjsno = cJSON_GetObjectItem(dayweather_cjson, "win_meter");
    cJSON* air_cjsno = cJSON_GetObjectItem(dayweather_cjson, "air");
    cJSON* pressure_cjsno = cJSON_GetObjectItem(dayweather_cjson, "pressure");
    cJSON* humidity_cjsno = cJSON_GetObjectItem(dayweather_cjson, "humidity");
    
    memcpy(dayweather.city, city_cjsno->valuestring, strlen(city_cjsno->valuestring));
    memcpy(dayweather.date, date_cjsno->valuestring, strlen(date_cjsno->valuestring));
    memcpy(dayweather.week, week_cjsno->valuestring, strlen(week_cjsno->valuestring));
    memcpy(dayweather.wea, wea_cjsno->valuestring, strlen(wea_cjsno->valuestring));
    memcpy(dayweather.wea_img, wea_img_cjsno->valuestring, strlen(wea_img_cjsno->valuestring));
    memcpy(dayweather.tem, tem_cjsno->valuestring, strlen(tem_cjsno->valuestring));
    memcpy(dayweather.tem_day, tem_day_cjsno->valuestring, strlen(tem_day_cjsno->valuestring));
    memcpy(dayweather.tem_night, tem_night_cjsno->valuestring, strlen(tem_night_cjsno->valuestring));
    memcpy(dayweather.win, win_cjsno->valuestring, strlen(win_cjsno->valuestring));
    memcpy(dayweather.win_speed, win_speed_cjsno->valuestring, strlen(win_speed_cjsno->valuestring));
    memcpy(dayweather.win_meter, win_meter_cjsno->valuestring, strlen(win_meter_cjsno->valuestring));
    memcpy(dayweather.air, air_cjsno->valuestring, strlen(air_cjsno->valuestring));
    memcpy(dayweather.pressure, pressure_cjsno->valuestring, strlen(pressure_cjsno->valuestring));
    memcpy(dayweather.humidity, humidity_cjsno->valuestring, strlen(humidity_cjsno->valuestring));
    
    char date_temp[12];
    strcpy(date_temp,dayweather.date);
    year_value = atoi(strtok(date_temp, "-"));
    month_value = atoi(strtok(NULL, "-"));
    day_value = atoi(strtok(NULL, "-"));

    if(strcmp(dayweather.week, "星期六")==0) wday_value = 0; 
    else if(strcmp(dayweather.week, "星期日")==0) wday_value = 1;
    else if(strcmp(dayweather.week, "星期一")==0) wday_value = 2;
    else if(strcmp(dayweather.week, "星期二")==0) wday_value = 3;
    else if(strcmp(dayweather.week, "星期三")==0) wday_value = 4;
    else if(strcmp(dayweather.week, "星期四")==0) wday_value = 5;
    else if(strcmp(dayweather.week, "星期五")==0) wday_value = 6;
    cJSON_Delete(root);
    return 1;
}


/**
 * @brief
 *
 * @param weather_data
 * @return char*
*/
char* compare_wea_output_img(char* weather_img)
{
    char* weather = weather_img;

    if (strncmp(weather, "xue", 3)==0) return &ui_img_xue_png;
    if (strncmp(weather, "lei", 3)==0) return &ui_img_lei_png;
    if (strncmp(weather, "shachen", 7)==0) return &ui_img_shachen_png;
    if (strncmp(weather, "wu", 2)==0) return &ui_img_wu_png;
    if (strncmp(weather, "bingbao", 7)==0) return &ui_img_bingbao_png;
    if (strncmp(weather, "yun", 3)==0) return &ui_img_yun_png;
    if (strncmp(weather, "yu", 2)==0) return &ui_img_yu_png;
    if (strncmp(weather, "yin", 3)==0) return &ui_img_yin_png;
    if (strncmp(weather, "qing", 4)==0) return &ui_img_qing_png;

    return &ui_img_qing_png;
}

char* compare_daywea_output_img(const char* weather_img)
{
    char* weather = weather_img;

    if (strncmp(weather, "xue", 3)==0) return &ui_img_xue_wd_png;
    if (strncmp(weather, "lei", 3)==0) return &ui_img_lei_w_png;
    if (strncmp(weather, "shachen", 7)==0) return &ui_img_shachen_w_png;
    if (strncmp(weather, "wu", 2)==0) return &ui_img_wu_w_png;
    if (strncmp(weather, "bingbao", 7)==0) return &ui_img_bingbao_w_png;
    if (strncmp(weather, "yun", 3)==0) return &ui_img_yun_wd_png;
    if (strncmp(weather, "yu", 2)==0) return &ui_img_yu_wd_png;
    if (strncmp(weather, "yin", 3)==0) return &ui_img_yin_w_png;
    if (strncmp(weather, "qing", 4)==0) return &ui_img_qing_wd_png;

    return &ui_img_qing_wd_png;
}

lv_img_dsc_t * compare_nightwea_output_img(const char* weather_img)
{
    char* weather = weather_img;

    if (strncmp(weather, "xue", 3)==0) return &ui_img_xue_wn_png;
    if (strncmp(weather, "lei", 3)==0) return &ui_img_lei_w_png;
    if (strncmp(weather, "shachen", 7)==0) return &ui_img_shachen_w_png;
    if (strncmp(weather, "wu", 2)==0) return &ui_img_wu_w_png;
    if (strncmp(weather, "bingbao", 7)==0) return &ui_img_bingbao_w_png;
    if (strncmp(weather, "yun", 3)==0) return &ui_img_yun_wn_png;
    if (strncmp(weather, "yu", 2)==0) return &ui_img_yu_wn_png;
    if (strncmp(weather, "yin", 3)==0) return &ui_img_yin_w_png;
    if (strncmp(weather, "qing", 4)==0) return &ui_img_qing_wn_png;

    return &ui_img_qing_wn_png;
}

void label_set_date(lv_obj_t * ui_date, char* date)
{
    char str_mon[4];
    char str_day[4];
    strtok(date, "-");
    strcpy(str_mon, strtok(NULL, "-"));
    strcpy(str_day, strtok(NULL, "-"));
    lv_label_set_text_fmt(ui_date,"%s/%s",str_mon,str_day);
}

void label_set_wea(lv_obj_t * ui_up_wea, lv_obj_t * ui_down_wea, lv_obj_t * ui_down_weapic, char* wea)
{
    char day_wea[13];
    char night_wea[13];
    char * change_pos;
    change_pos = strstr(wea,"转");
    if(change_pos != NULL)
    {
        strncpy(day_wea, wea, change_pos-wea);  //不会自动加上终止符
        day_wea[change_pos-wea] = '\0';
        strcpy(night_wea,change_pos+2);
    }
    else
    {
        strcpy(day_wea, wea);
        strcpy(night_wea, wea);
    }

    lv_label_set_text(ui_up_wea,day_wea);
    lv_label_set_text(ui_down_wea,night_wea);
    
	if (strstr(night_wea, "雪") != NULL)
	{
		lv_img_set_src(ui_down_weapic, &ui_img_xue_wn_png);
	}
    else if(strstr(night_wea, "雷") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_yu_wn_png);   //只有雷阵雨，但也是用雨的图标
    }
    else if(strstr(night_wea, "沙") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_shachen_w_png);
    }
    else if(strstr(night_wea, "尘") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_shachen_w_png);
    }    
    else if(strstr(night_wea, "雾") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_wu_w_png);
    }    
    else if(strstr(night_wea, "霾") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_wu_w_png);
    }
    else if(strstr(night_wea, "雹") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_bingbao_w_png);
    } 
    else if(strstr(night_wea, "云") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_yun_wn_png);
    } 
    else if(strstr(night_wea, "雨") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_yu_wn_png);
    } 
    else if(strstr(night_wea, "阴") != NULL)
    {
        lv_img_set_src(ui_down_weapic, &ui_img_yin_w_png);
    } 
    else
    {
        lv_img_set_src(ui_down_weapic, &ui_img_qing_wn_png);
    } 

}


/**
 * @brief  void queue_task(void* arg)
 * 消息队列循环读取
 * @param arg
*/
static void queue_task(void* arg)
{
    char* queue_buff = NULL;
    char* ssid = NULL;
    char* password = NULL;
    char* cflag = NULL;
    char* appid = NULL;
    char* appsecret = NULL;
    char* ipv4_addr = NULL;
    //lv_ui* ui = (lv_ui*)arg;
    ssid = flash_get_data(SSID_KEY, 32);
    password = flash_get_data(PASS_KEY, 32);
    cflag = flash_get_data(CONNECT_FLAG, 1);
    appid = flash_get_data(WEATHER_ID, 64);
    appsecret = flash_get_data(WEATHER_SECRET, 64);

    if (ssid!=NULL)
    {
        lv_textarea_set_text(ui_TextArea1,ssid);
    }
    if (password!=NULL)
    {
        lv_textarea_set_text(ui_TextArea2,password);
    }
    if (appid!=NULL)
    {
        lv_textarea_set_text(ui_TextArea3,appid);
    }
    if (appsecret!=NULL)
    {
        lv_textarea_set_text(ui_TextArea4,appsecret);
    }

    if(appid!=NULL && appsecret!=NULL)
    {
        //&appid=475XXXX&appsecret=dL1XXXX
        sprintf(user_weather_path,"&appid=%s&appsecret=%s",lv_textarea_get_text(ui_TextArea3), lv_textarea_get_text(ui_TextArea4));
        strcpy(Week_Weather_PATH, HTTP_WEEK_PATH);
        strcat(Week_Weather_PATH, user_weather_path);
        strcpy(Day_Weather_PATH, HTTP_DAY_PATH);
        strcat(Day_Weather_PATH, user_weather_path);
    }

    if(*cflag!=1)
    {
        lv_obj_clear_state(ui_Switch1, LV_STATE_CHECKED);
    }

    if (ssid!=NULL && password!=NULL && appid!=NULL && appsecret!=NULL && *cflag==1)
    {
        lv_obj_add_state(ui_Switch1, LV_STATE_CHECKED);
        _ui_flag_modify(ui_Spinner1, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_Cover1, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_SP1Button, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
        
        char* buff = pvPortMalloc(256);
        if(lv_textarea_get_text(ui_TextArea1)!=NULL && lv_textarea_get_text(ui_TextArea2)!=NULL)
        {
            sprintf(buff, "{\"WiFi\":{\"ssid\":\"%s\",\"password\":\"%s\"}}", lv_textarea_get_text(ui_TextArea1), lv_textarea_get_text(ui_TextArea2));
            xQueueSend(queue, (void*)buff, portMAX_DELAY);
        }
        vPortFree(buff);
    }

    while (1)
    {
        queue_buff = pvPortMalloc(1024*2);   //1024*2
        memset(queue_buff, 0, 1024*2);  //1024*2

        xQueueReceive(queue, queue_buff, portMAX_DELAY);

        switch (cjson__analysis_type(queue_buff))
        {
            case 1:    //链接WiFi

                sprintf(user_weather_path,"&appid=%s&appsecret=%s",lv_textarea_get_text(ui_TextArea3), lv_textarea_get_text(ui_TextArea4));
                strcpy(Week_Weather_PATH, HTTP_WEEK_PATH);
                strcat(Week_Weather_PATH, user_weather_path);
                strcpy(Day_Weather_PATH, HTTP_DAY_PATH);
                strcat(Day_Weather_PATH, user_weather_path);
                flash_erase_set(WEATHER_ID, lv_textarea_get_text(ui_TextArea3));
                flash_erase_set(WEATHER_SECRET, lv_textarea_get_text(ui_TextArea4));


                ssid = cjson_analysis_ssid(queue_buff);
                password = cjson_analysis_password(queue_buff);
                printf("[%s]:ssid=%s password:%s\r\n", __func__, ssid, password);
                wifi_connect(ssid, password);
                break;
                
            case 2:    //WiFi连接成功  接收ip地址

                ipv4_addr = cjson__analysis_ip(queue_buff);
                printf("[%s] ipv4 addr=%s\r\n", __func__, ipv4_addr);
                memset(queue_buff, 0, 1024*2);
                sprintf(queue_buff, "IP:%s", ipv4_addr);
                
                vPortFree(ssid);
                vPortFree(password);
                vPortFree(ipv4_addr);


                if (https_Handle!=NULL) {
                    vTaskDelete(https_Handle);
                }
                
                xTaskCreate(https_get_weather_task, "https task", 1024*6, NULL, 3, &https_Handle);

                lv_timer_create((void*)send_event, 1000, NULL);
                //lv_disp_load_scr(ui_Screen2);
                break;       
                
            case 3:     //接收天气情况
                
                if(cjson_get_weather(queue_buff)!=0)
                {
                    lv_label_set_text(ui_Area,weathers[0].city);
                    lv_label_set_text(ui_Weather12,weathers[0].wea);
                    lv_label_set_text_fmt(ui_Weather13,"%s°/ %s°",weathers[0].tem_day,weathers[0].tem_night);
                    lv_label_set_text(ui_Weather22,weathers[1].wea);
                    lv_label_set_text_fmt(ui_Weather23,"%s°/ %s°",weathers[1].tem_day,weathers[1].tem_night);
                    
                    lv_img_set_src(ui_weatherpic1, compare_wea_output_img(weathers[0].wea_img));
                    lv_img_set_src(ui_weatherpic2, compare_wea_output_img(weathers[1].wea_img));

                    lv_label_set_text_fmt(ui_UL2,"周%s",week_day[(wday_value+1)%7]);
                    lv_label_set_text_fmt(ui_UL3,"周%s",week_day[(wday_value+2)%7]);
                    lv_label_set_text_fmt(ui_UL4,"周%s",week_day[(wday_value+3)%7]);
                    lv_label_set_text_fmt(ui_UL5,"周%s",week_day[(wday_value+4)%7]);
                    lv_label_set_text_fmt(ui_UL6,"周%s",week_day[(wday_value+5)%7]);
                    lv_label_set_text_fmt(ui_UL7,"周%s",week_day[(wday_value+6)%7]);

                    label_set_date(ui_UDL1, weathers[0].date);
                    label_set_date(ui_UDL2, weathers[1].date);
                    label_set_date(ui_UDL3, weathers[2].date);
                    label_set_date(ui_UDL4, weathers[3].date);
                    label_set_date(ui_UDL5, weathers[4].date);
                    label_set_date(ui_UDL6, weathers[5].date);
                    label_set_date(ui_UDL7, weathers[6].date);

                    label_set_wea(ui_UWL1, ui_DWL1, ui_weanImage1, weathers[0].wea);
                    label_set_wea(ui_UWL2, ui_DWL2, ui_weanImage2, weathers[1].wea);
                    label_set_wea(ui_UWL3, ui_DWL3, ui_weanImage3, weathers[2].wea);
                    label_set_wea(ui_UWL4, ui_DWL4, ui_weanImage4, weathers[3].wea);
                    label_set_wea(ui_UWL5, ui_DWL5, ui_weanImage5, weathers[4].wea);
                    label_set_wea(ui_UWL6, ui_DWL6, ui_weanImage6, weathers[5].wea);
                    label_set_wea(ui_UWL7, ui_DWL7, ui_weanImage7, weathers[6].wea);

                    lv_coord_t tem_h = dayweather_array[0];
                    lv_coord_t tem_l = nightweather_array[0];
                    for (int i=0; i<7; i++)
                    {
                        if(dayweather_array[i]>tem_h)
                        {
                            tem_h = dayweather_array[i]; 
                        }

                        if(nightweather_array[i]<tem_l)
                        {
                            tem_l = nightweather_array[i];
                        }
                    }
                    lv_chart_set_range(ui_Chart1, LV_CHART_AXIS_PRIMARY_Y, tem_l, tem_h);
                    lv_chart_set_ext_y_array(ui_Chart1, ui_Chart1_series_1, dayweather_array);
                    lv_chart_set_ext_y_array(ui_Chart1, ui_Chart1_series_2, nightweather_array);



                    lv_label_set_text_fmt(ui_UTL1, "%s°", weathers[0].tem_day);
                    lv_label_set_text_fmt(ui_UTL2, "%s°", weathers[1].tem_day);
                    lv_label_set_text_fmt(ui_UTL3, "%s°", weathers[2].tem_day);
                    lv_label_set_text_fmt(ui_UTL4, "%s°", weathers[3].tem_day);
                    lv_label_set_text_fmt(ui_UTL5, "%s°", weathers[4].tem_day);
                    lv_label_set_text_fmt(ui_UTL6, "%s°", weathers[5].tem_day);
                    lv_label_set_text_fmt(ui_UTL7, "%s°", weathers[6].tem_day);

                    lv_img_set_src(ui_weadImage1, compare_daywea_output_img(weathers[0].wea_img));
                    lv_img_set_src(ui_weadImage2, compare_daywea_output_img(weathers[1].wea_img));
                    lv_img_set_src(ui_weadImage3, compare_daywea_output_img(weathers[2].wea_img));
                    lv_img_set_src(ui_weadImage4, compare_daywea_output_img(weathers[3].wea_img));
                    lv_img_set_src(ui_weadImage5, compare_daywea_output_img(weathers[4].wea_img));
                    lv_img_set_src(ui_weadImage6, compare_daywea_output_img(weathers[5].wea_img));
                    lv_img_set_src(ui_weadImage7, compare_daywea_output_img(weathers[6].wea_img));

                    lv_label_set_text_fmt(ui_DTL1, "%s°", weathers[0].tem_night);
                    lv_label_set_text_fmt(ui_DTL2, "%s°", weathers[1].tem_night);
                    lv_label_set_text_fmt(ui_DTL3, "%s°", weathers[2].tem_night);
                    lv_label_set_text_fmt(ui_DTL4, "%s°", weathers[3].tem_night);
                    lv_label_set_text_fmt(ui_DTL5, "%s°", weathers[4].tem_night);
                    lv_label_set_text_fmt(ui_DTL6, "%s°", weathers[5].tem_night);
                    lv_label_set_text_fmt(ui_DTL7, "%s°", weathers[6].tem_night);
                }
                break;

            case 4:
                if(cjson_get_dayweather(queue_buff)!=0)
                {
                    lv_label_set_text_fmt(ui_Temp,"%s°",dayweather.tem);
                    lv_label_set_text(ui_Weanow,dayweather.wea);
                    lv_img_set_src(ui_WeaImage, compare_wea_output_img(dayweather.wea_img));
                    char air_q[10];
                    if(atoi(dayweather.air)<50)
                    {
                        strcpy(air_q,"优");
                    }
                    else if(atoi(dayweather.air)<100)
                    {
                        strcpy(air_q,"良");
                    }
                    else if(atoi(dayweather.air)<150)
                    {
                        strcpy(air_q,"轻度污染");
                    }
                    else if(atoi(dayweather.air)<200)
                    {
                        strcpy(air_q,"中度污染");
                    }
                    else if(atoi(dayweather.air)<300)
                    {
                        strcpy(air_q,"重度污染");
                    }
                    else
                    {
                        strcpy(air_q,"严重污染");
                    }
                    lv_label_set_text_fmt(ui_Air,"周%s %s°/%s°   空气: %s %s",week_day[wday_value],dayweather.tem_day,dayweather.tem_night,air_q,dayweather.air);
                    lv_label_set_text_fmt(ui_Win,"%s %s",dayweather.win,dayweather.win_speed);
                    lv_label_set_text_fmt(ui_WinSpeed,"风速: %s",dayweather.win_meter);
                    lv_label_set_text_fmt(ui_Humidity,"%s",dayweather.humidity);
                    int i_humidity = 0;
                    for(int i=0; i<3;i++)
                    {
                        if(dayweather.humidity[i]!='%')
                        {
                            i_humidity *= 10; 
                            i_humidity += dayweather.humidity[i]-'0';
                        }
                        else
                        {
                            break;
                        }
                    }
                    lv_slider_set_value(ui_HumSlider, i_humidity, LV_ANIM_OFF);
                    lv_label_set_text_fmt(ui_Pressure,"气压:%s百帕",dayweather.pressure);
                    
                    if(first_connect_flag==0) first_connect_flag = 1;
                }
                break;
            default:
                break;
        }
        vPortFree(queue_buff);
    }
}

void user_queue_init(void)//(lv_ui* ui)
{
    /* Add your codes here */
    queue = xQueueCreate(1, 1024*2);
    xTaskCreate(queue_task, "queue task", 1024*6, NULL, 2, NULL);
    http_timers = xTimerCreate("http_timers", pdMS_TO_TICKS(1000), pdTRUE, (void*)0, http_hour_requst_time);
}

void wifi_event_handler(uint32_t code)
{

    sta_ConnectStatus = code;
    switch (code) {
        case CODE_WIFI_ON_INIT_DONE:
        {
            wifi_mgmr_init(&conf);
        }
        break;
        case CODE_WIFI_ON_MGMR_DONE:
        {
            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_MGMR_DONE\r\n", __func__);
        }
        break;
        case CODE_WIFI_ON_SCAN_DONE:
        {
            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_SCAN_DONE\r\n", __func__);
            wifi_mgmr_sta_scanlist();
        }
        break;
        case CODE_WIFI_ON_CONNECTED:
        {
            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_CONNECTED\r\n", __func__);
            void mm_sec_keydump();
            mm_sec_keydump();
        }
        break;
        case CODE_WIFI_ON_GOT_IP:
        {

            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
        }
        break;
        case CODE_WIFI_ON_DISCONNECT:
        {
            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);
        }
        break;
        case CODE_WIFI_ON_AP_STARTED:
        {
            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STARTED\r\n", __func__);
        }
        break;
        case CODE_WIFI_ON_AP_STOPPED:
        {
            //LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STOPPED\r\n", __func__);
        }
        break;
        case CODE_WIFI_ON_AP_STA_ADD:
        {
            //LOG_I("[APP] [EVT] [AP] [ADD] %lld\r\n", xTaskGetTickCount());
        }
        break;
        case CODE_WIFI_ON_AP_STA_DEL:
        {
            //LOG_I("[APP] [EVT] [AP] [DEL] %lld\r\n", xTaskGetTickCount());
        }
        break;
        default:
        {
            //LOG_I("[APP] [EVT] Unknown code %u \r\n", code);
        }
    }
}